package com.cf.rpsm_admin.Pojo;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
//import io.swagger.models.auth.In;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

@Data
public final class PageResult<T> {
    private final Integer pageNum;
    private final Integer pageSize;
    private final Long total;
    private final List<T> list;

    private PageResult(@NotNull Integer pageNum, @NotNull Integer pageSize, @NotNull Long total, @NotNull List<T> list) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;
        this.list = list;
    }
    public static <T> PageResult<T> restPage(@NotNull Integer pageNum,@NotNull Integer pageSize,@NotNull Long total,@NotNull List<T> list){
        return new PageResult<>(pageNum,pageSize,total, Optional.ofNullable(list).orElse(Collections.emptyList()));
    }

    public static <T> PageResult<T> restPage(@NotNull Page<T> page){
        return new PageResult<>(page.getPageNum(),page.getPageSize(),page.getTotal(),page.getResult());
    }
    public static <T> PageResult<T> restPage(@NotNull PageInfo<T> page){
        return new PageResult<>(page.getPageNum(),page.getPageSize(),page.getTotal(),page.getList());
    }

}
